package com.motong.gongdan.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.motong.gongdan.entity.Mission;
import com.motong.gongdan.vo.H5Resp.*;
import com.motong.gongdan.vo.H5Vo.common.GroupCountVo;
import com.motong.gongdan.vo.H5Vo.mission.query.H5MissionListQuery;
import com.motong.gongdan.vo.resp.*;
import org.apache.ibatis.annotations.Param;

import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;

public interface MissionMapper extends BaseMapper<Mission> {
    IPage<MissionListResp> getList(IPage<MissionListResp> page, @Param(Constants.WRAPPER) Wrapper<MissionListResp> wrapper);

    List<MissionListResp> getListO(@Param(Constants.WRAPPER) Wrapper<MissionListResp> wrapper);

    MissionListResp getMissionOne(@Param(Constants.WRAPPER) Wrapper<MissionListResp> wrapper);

    List<ProcessNumberResp> getProcessNumberData(@Param(Constants.WRAPPER) Wrapper<ProcessNumberResp> wrapper);

    IPage<ProduceTaskMessResp> getProduceTaskMess(Page page, @Param(Constants.WRAPPER) Wrapper<ProduceTaskMessResp> wrapper, @Param("time") String time, @Param("type") Integer type);

    List<H5WorkOrderDetailResp> getProcessByWorkOrder(@Param(Constants.WRAPPER) Wrapper<H5WorkOrderDetailResp> wrapper, @Param("ids") List<String> ids);

    IPage<H5MissionResp> getWorkReportList(Page page, @Param("intersection") List<Integer> intersection
            , @Param("type") Integer type, @Param("userId") Integer loginUserId,
                                           @Param("startTime") Date startTime, @Param("endTime") Date endTime
            , @Param("sortProp") String sortProp, @Param("sortOrd") String sortOrd);

    Long getCountByTime(@Param("intersection") List<Integer> intersection, @Param("type") Integer type, @Param("userId") Integer loginUserId,
                        @Param("startTime") Date startTime, @Param("endTime") Date endTime);

    H5MissionDetailResp getMissionDetails(@Param("workReportId") Integer workReportId);

    List<H5MissionResp> getWorkReports(@Param("userId") Integer userId, @Param("startTime") Date startTime, @Param("endTime") Date endTime);

    IPage<H5ProductiveTaskResp> getMyOrStaffMissions(IPage<H5ProductiveTaskResp> h5ProductiveTaskVoPage, @Param(Constants.WRAPPER) Wrapper<H5ProductiveTaskResp> wrapper, @Param("userId") Integer userId,
                                                     @Param("seek") String seek,
                                                     @Param("sortProp") String sortProp, @Param("sortOrder") String sortOrder, @Param("startTime") Date startTime,
                                                     @Param("endTime") Date endTime,
                                                     @Param("screen") Integer screen,
                                                     @Param("flag") Integer flag);

//    IPage<H5ProductiveTaskResp> getStaffMissions(IPage<H5ProductiveTaskResp> h5ProductiveTaskVoPage, @Param(Constants.WRAPPER) Wrapper<H5ProductiveTaskResp> wrapper, @Param("userId") Integer userId,
//                                                @Param("seek") String seek,
//                                                @Param("sortProp") String sortProp, @Param("sortOrder") String sortOrder, @Param("startTime")Date startTime,
//                                                @Param("endTime") Date endTime,
//                                                @Param("screen") Integer screen);


    H5ProductiveTaskDetailResp getProductionDetail(@Param("processId") Integer missionId);

    H5OrderDataResp getOrderData(@Param("orderCode") String orderCode);

    List<WOMissionResp> getWODetailMission(@Param(Constants.WRAPPER) Wrapper<WOMissionResp> wrapper);

    MissionListResp getMissionDetail(@Param(Constants.WRAPPER) Wrapper<MissionListResp> wrapper);


    String getBadProductListByMissionId(@Param("missionId") Integer missionId, @Param("loginUserFactory") Integer loginUserFactory);

    H5DataResp getWorkReportData(@Param("intersection") List<Integer> intersection
            , @Param("userId") Integer loginUserId, @Param("startTime") Date startTime, @Param("endTime") Date endTime);

    IPage<H5ProductiveTaskResp> getProcess(IPage<H5ProductiveTaskResp> h5ProductiveTaskVoPage, @Param(Constants.WRAPPER) Wrapper<H5ProductiveTaskResp> wrapper, @Param("processCode") String processCode,
                                           @Param("seek") String seek,
                                           @Param("sortProp") String sortProp, @Param("sortOrder") String sortOrder, @Param("startTime") Date startTime,
                                           @Param("endTime") Date endTime,
                                           @Param("screen") Integer screen,
                                           @Param("userId") Integer userId);

    IPage<H5ProductiveTaskResp> getDistributionList(IPage<H5ProductiveTaskResp> h5ProductiveTaskVoPage, @Param(Constants.WRAPPER) Wrapper<H5ProductiveTaskResp> wrapper,
                                                    @Param("seek") String seek,
                                                    @Param("sortProp") String sortProp, @Param("sortOrder") String sortOrder, @Param("startTime") Date startTime,
                                                    @Param("endTime") Date endTime,
                                                    @Param("screen") Integer screen);


    List<Integer> getProcessIds(@Param("startTime") Date startTime, @Param("endTime") Date endTime, @Param("screen") String screen);

    /**
     * 根据工单编码获取分组数量
     *
     * @param workOrderCodes 工单编码集合
     * @return 工单编码(数量)信息
     */
    List<Map<String, Object>> getCountGroupByWorkOrder(@Param("workOrderCodes") Set<String> workOrderCodes);

    /**
     * 根据参数名称获取分组数量
     *
     * @param intersection 工单编码集合
     * @return 工单编码(数量)信息
     */
    List<Map<String, Object>> getGroupCount(@Param("intersection") List<Integer> intersection, @Param("type") Integer type, @Param("userId") Integer loginUserId,
                                            @Param("startTime") Date startTime, @Param("endTime") Date endTime, @Param("groupName") String groupName);

    /**
     * 获取任务列表(默认剔除状态为0的数据)
     *
     * @param mergeSearchResult 查询条件
     * @return 任务列表
     */
    Page<MissionListResp> getH5MissionList(Page<Mission> page, @Param("condition") H5MissionListQuery mergeSearchResult, @Param("isH5") boolean isH5);

    /**
     * 获取分类统计数量
     *
     * @param mergeSearchResult 查询条件
     * @return 类型数量映射
     */
    List<GroupCountVo> getTypeCountMap(@Param("condition") H5MissionListQuery mergeSearchResult, @Param("groupColumn") String groupColumn, @Param("isH5") boolean isH5);

    long getGroupCountVo(@Param("query") H5MissionListQuery query, @Param("isH5") boolean isH5);

}
